package com.wazzapps.sdk;

import android.content.SharedPreferences;

public class ConsentState {
    public static final int ALLOW_PERSONALISED = 2;
    public static final int DENY_PERSONALISED = 3;
    public static final String ISUNDERLAW_KEY = "cdg43g3g44g45h_underlaw";
    public static final String PERSONALISATION_KEY = "cdg43g3g44g45h_personalisation";
    public static final int POLICY_SHOWN = 1;
    public static final int UNDEFINED = 0;
    public static final String USERAGE_KEY = "cdg43g3g44g45h_age";
    private static ConsentState instance;
    public boolean isUnderLaw = false;
    public int personalisation = 0;
    public int userAge = 0;

    private static ConsentState getInstance() {
        if (instance == null) {
            instance = new ConsentState();
        }
        return instance;
    }

    public static ConsentState getState(SharedPreferences sharedPreferences) {
        getInstance().personalisation = sharedPreferences.getInt(PERSONALISATION_KEY, 0);
        getInstance().userAge = sharedPreferences.getInt(USERAGE_KEY, 0);
        getInstance().isUnderLaw = sharedPreferences.getBoolean(ISUNDERLAW_KEY, false);
        return getInstance();
    }

    public static void setState(SharedPreferences sharedPreferences, ConsentState consentState) {
        SharedPreferences.Editor edit = sharedPreferences.edit();
        edit.putInt(PERSONALISATION_KEY, consentState.personalisation);
        edit.putInt(USERAGE_KEY, consentState.userAge);
        edit.putBoolean(ISUNDERLAW_KEY, consentState.isUnderLaw);
        edit.commit();
    }
}